﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace Sahibinden.UserControl
{
    public partial class MenuType : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UstkategoriDoldur();
        }

        SqlConnection con = new SqlConnection("Data Source=10.5.25.24;Initial Catalog=sahibinden;User Id=hakan;Password=123;");

        private void UstkategoriDoldur()
        {
            SqlDataAdapter da = new SqlDataAdapter("select * from MenuType where UstKategoriID is null", con);

            DataTable dt = new DataTable();

            da.Fill(dt);

            Repeater1.DataSource = dt;

            Repeater1.DataBind();

        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Repeater altKategoriler = e.Item.FindControl("Repeater2") as Repeater;

            SqlDataAdapter da = new SqlDataAdapter("Select * From MenuType where ustKategoriID =@ID", con);

            da.SelectCommand.Parameters.AddWithValue("@ID", DataBinder.Eval(e.Item.DataItem, "KategoriID"));

            DataTable dt = new DataTable();

            da.Fill(dt);

            if (dt.Rows.Count == 0)
            {
                (e.Item.FindControl("menuBaslik") as HtmlControl).Attributes["Class"] = "menuitem";
            }
            altKategoriler.DataSource = dt;
            altKategoriler.DataBind();

        }
    }
}